//
//  MKTabBar.m
//  Weibo_OC
//
//  Created by mac on 16/1/11.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "MKTabBar.h"

@interface MKTabBar ()


@end

@implementation MKTabBar


- (instancetype)init {
    
    if (self = [super init]) {
     
        [self addSubview:self.plusButton];
    }
    
    return  self;
}

- (UIButton *)plusButton {
    if (_plusButton == nil) {
        _plusButton = [[UIButton alloc] init];
        
        [_plusButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_plusButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_plusButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_plusButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [_plusButton sizeToFit];
        
    }
    
    return _plusButton;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    CGFloat itemW = self.bounds.size.width * 0.2;
    CGFloat itemH = self.bounds.size.height;
    CGRect baseRect = CGRectMake(0, 0, itemW, itemH);
    NSInteger index = 0;
    for ( UIView *subView in self.subviews) {
        
        if ([subView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            subView.frame = CGRectOffset(baseRect, index * itemW, 0);
            
            index += (index == 1? 2 : 1);
        }
    }
    
    self.plusButton.frame = CGRectOffset(baseRect, 2 * itemW, 0);
    
}















@end
